  const app=getApp()
Page({
  goLogin() {
    wx.navigateTo({
      url: '/pages/login/index',
    })
  },
  onShow(){
    //用户不登录时不必请求
    app.token &&this.getUserProfile()
    
  },
  async getUserProfile(){
    const {code,data:{avatar,nickName}}= await wx.http.get('/userInfo')
    if(code !==10000) return wx.utils.toast()
    this.setData({
      avatar,
      nickName
    })
        // 将头像和昵称存到应用实例中
        app.userProfile={avatar,nickName}
  },
})
